package com.hgc.ch03;

import java.util.concurrent.atomic.AtomicReference;

/**
 * Created by 01367627 on 2019/7/10.
 */
public class AtomicReferenceExample {

    private static class UserInfo {
        private Long id;
        private String name;

        public UserInfo(Long id, String name) {
            this.id = id;
            this.name = name;
        }

        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        @Override
        public String toString() {
            return "GoodsInfo=============UserId:" + id + ",UserName:" + name;
        }
    }

    public static void main(String[] args) {
        UserInfo u = new UserInfo(1L,"Dog Li");
        System.out.println(u);
        AtomicReference<UserInfo> ar = new AtomicReference<>(u);
        //System.out.println(ar.getAndSet(new GoodsInfo(2L,"Dog Ti")));
        System.out.println(ar.compareAndSet(u,new UserInfo(3L,"Dog Ri")));
        System.out.println(ar.get());
    }

}
